package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.BankAccount;
import com.ruoyi.erp.service.IBankAccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 银行账户Controller
 * 
 * @author sauger
 * @date 2022-04-01
 */
@Controller
@RequestMapping("/erp/bank")
public class BankAccountController extends BaseController
{
    private String prefix = "erp/bank";

    @Autowired
    private IBankAccountService bankAccountService;

    @RequiresPermissions("erp:bank:view")
    @GetMapping()
    public String bank()
    {
        return prefix + "/bank";
    }

    /**
     * 查询银行账户列表
     */
    @RequiresPermissions("erp:bank:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BankAccount bankAccount)
    {
        startPage();
        List<BankAccount> list = bankAccountService.selectBankAccountList(bankAccount);
        return getDataTable(list);
    }

    /**
     * 导出银行账户列表
     */
    @RequiresPermissions("erp:bank:export")
    @Log(title = "银行账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BankAccount bankAccount)
    {
        List<BankAccount> list = bankAccountService.selectBankAccountList(bankAccount);
        ExcelUtil<BankAccount> util = new ExcelUtil<BankAccount>(BankAccount.class);
        return util.exportExcel(list, "银行账户数据");
    }

    /**
     * 新增银行账户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存银行账户
     */
    @RequiresPermissions("erp:bank:add")
    @Log(title = "银行账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BankAccount bankAccount)
    {
        return toAjax(bankAccountService.insertBankAccount(bankAccount));
    }

    /**
     * 修改银行账户
     */
    @RequiresPermissions("erp:bank:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BankAccount bankAccount = bankAccountService.selectBankAccountById(id);
        mmap.put("bankAccount", bankAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存银行账户
     */
    @RequiresPermissions("erp:bank:edit")
    @Log(title = "银行账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BankAccount bankAccount)
    {
        return toAjax(bankAccountService.updateBankAccount(bankAccount));
    }

    /**
     * 删除银行账户
     */
    @RequiresPermissions("erp:bank:remove")
    @Log(title = "银行账户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bankAccountService.deleteBankAccountByIds(ids));
    }
}
